package br.com.gsh.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.gsh.pojo.Twitter;
import br.com.gsh.service.TwitterService;

public class ReTwittaServlet extends HttpServlet{

	private static final long serialVersionUID = -154340731751042775L;
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		String nick = request.getParameter("nickUsuario");
		String nickSession = request.getParameter("nickSession");
		String respTwitter = request.getParameter("tuitter");
		
//		Usuario dadosUser = (Usuario) request.getSession().getAttribute("user");
		
		String resposta = "RT " + respTwitter;
		
		TwitterService service = new TwitterService();
		Twitter twit = new Twitter();

		twit.setMensagem(resposta);
		twit.setIdUsuario(nick);
		twit.setReTuitou(nickSession);
		
		try {
			service.adicionaReTuit(twit);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		response.sendRedirect("/Twitter/listTwitterServlet");
		
	}

}
